home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / tpwprog5.arj / CLINES.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-02  |  1.8 KB  |  82 lines

  1. { clines.pas -- Draw colored lines at random }
  2.  
  3. program CLines;
  4.  
  5. uses WinTypes, WinProcs, WObjects;
  6.  
  7. const
  8.  
  9.   timer_ID = 1;
  10.  
  11. type
  12.  
  13.   LineApplication = object(TApplication)
  14.     procedure InitMainWindow; virtual;
  15.   end;
  16.  
  17.   PLineWindow = ^LineWindow;
  18.   LineWindow = object(TWindow)
  19.     procedure SetupWindow; virtual;
  20.     procedure WMDestroy(var Msg: TMessage);
  21.       virtual wm_First + wm_Destroy;
  22.     procedure WMTimer(var Msg: TMessage);
  23.       virtual wm_First + wm_Timer;
  24.   end;
  25.  
  26. {- Initialize the application's window }
  27. procedure LineApplication.InitMainWindow;
  28. begin
  29.   MainWindow := New(PLineWindow, Init(nil, 'Random Colored Lines'))
  30. end;
  31.  
  32. {- Initialize the window's actions }
  33. procedure LineWindow.SetupWindow;
  34. begin
  35.   TWindow.SetupWindow;
  36.   SetTimer(HWindow, timer_ID, 100, nil)
  37. end;
  38.  
  39. {- Intercept wm_Destroy message }
  40. procedure LineWindow.WMDestroy(var Msg: TMessage);
  41. begin
  42.   KillTimer(HWindow, timer_ID);
  43.   TWindow.WMDestroy(Msg)
  44. end;
  45.  
  46. {- React to timer events }
  47. procedure LineWindow.WMTimer(var Msg: TMessage);
  48. var
  49.   Dc: HDC;
  50.   R: TRect;
  51.   OldPen, Pen: HPen;
  52.   Color: TColorRef;
  53. begin
  54.   Dc := GetDC(HWindow);
  55.   GetClientRect(HWindow, R);
  56.   Color := RGB(Random(256), Random(256), Random(256));
  57.   Pen := CreatePen(ps_Solid, 1, Color);
  58.   OldPen := SelectObject(Dc, Pen);
  59.   MoveTo(Dc, Random(R.right), Random(R.bottom));
  60.   LineTo(Dc, Random(R.right), Random(R.bottom));
  61.   SelectObject(Dc, OldPen);
  62.   DeleteObject(Pen);
  63.   ReleaseDC(hWindow, Dc)
  64. end;
  65.  
  66. var
  67.  
  68.   LineApp: LineApplication;
  69.  
  70. begin
  71.   LineApp.Init('LineApp');
  72.   LineApp.Run;
  73.   LineApp.Done
  74. end.
  75.  
  76.  
  77. {--------------------------------------------------------------
  78.   Copyright (c) 1991 by Tom Swan. All rights reserved.
  79.   Revision 1.00    Date: 2/20/1991
  80. ---------------------------------------------------------------}
  81.  
  82.